<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%     
	String path = request.getContextPath();     
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";     
%>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>修改用户密码</title>
	<base href="<%=basePath%>"/>
	<%@ include file="../../cuv_include.jsp"%>
	<style type="text/css"> 
	  fieldset,legend,form,table,tr,td,textarea{margin:0;padding:0}
	  form label {font-weight:bold;}
	  table{margin:10px 10px};
	  td{line-height: 40px;}
	  input[type="text"]{width:250px;}
	  input[type="password"]{width:250px;}
	</style>

<script type="text/javascript">
  $(function(){
      var options = {dataType: 'json', beforeSubmit: beforeSubmit, success: process};
      $("#userForm").submit(function(){
          $(this).ajaxSubmit(options);
          return false;
      });
  });
  
  function beforeSubmit() {
      if(isEmpty($("#password1").val())) { alert("密码不能为空！"); return false; }
      if(isEmpty($("#password2").val())) { alert("确认密码不能为空！"); return false; }
      
      if(!validatePassword($("#password1").val(), 4, 22)) { alert("密码不符合规格！"); return false; }
      if(!validatePassword($("#password2").val(), 4, 22)) { alert("确认密码不符合规格！"); return false; }	
      
      if($("#password1").val() != $("#password2").val()) { alert("两次密码不一致！"); return false; }
	  return true;
  }

  function process(responseJson) {
      if(responseJson.code == 0) {
          $('#error_label').text("错误信息：" + responseJson.message);
          $("#p_error").show();
          return;
      }
      var qs = $("#qs").val();
      location.href = "<%=basePath%>system/user/list.do?" + qs;
  }  
</script>
</head>
<body>
  <div>
    <fieldset>
      <legend>修改用户密码：</legend>
      <form id="userForm" method="post" action="system/user/password.do">
      	<input id="qs" name="qs" type="hidden" value="${qs}"/>
      	<p id = "p_error" style = "margin:10px 10px;">
      	    <label id="error_label" style="color:red;"></label>
      	</p>
        <table>
          <tr>
            <td><label for="enname">英文名称：</label></td>
            <td>
            	<input type="text" name="enname" id="enname" disabled="disabled" value="${user.enname }" />
                <input type="hidden" name="enname" id="enname" value="${user.enname }" />
            </td>
          </tr>
          <tr>
            <td><label for="password1">密码：</label></td>
            <td>
            	<input type="text" name="password1" id="password1" value="" />
            	<font color="red">&nbsp;*&nbsp;&nbsp;</font>
            	<label for="password1">只能由字母、数字、[_~!@#$%^&*+-]组成，字母开始，4～22位</label>
            </td>
          </tr>    
          <tr>
            <td><label for="password2">确认密码：</label></td>
            <td>
              <input type="text" name="password2" id="password2" value="" />
              <font color="red">&nbsp;*&nbsp;&nbsp;</font>
              <label for="password2">只能由字母、数字、[_~!@#$%^&*+-]组成，字母开始，4～22位</label>
            </td>
          </tr>  
          <tr>
            <td></td>
            <td>
            	<input type="submit" id="btn_insert" value="提交" style="width:80px;" />
            	<input type="button" id="btn_back" value="返回" onclick="history.back();" style="width:80px;" />
            </td>
          </tr>
        </table>
      </form>
    </fieldset>
  </div>
</body>
</html>